package org.entities;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Polygon;
import org.newdawn.slick.geom.Vector2f;

// ====================================
// a generic class for all game objects
// ====================================

public abstract class LevelObject {

    public float x;
    public float y;
    public float tempX;
    public float tempY;
    public String type;
    public Polygon poly;
    public int shields;
    public static int MAX_SHIELDS;
    public Vector2f vec=new Vector2f(1,0.6f);
    public Vector2f vec2=new Vector2f(1,1.8f);
    public String lastFacingDirection;
    public boolean 
    moveLeft,
    moveRight,
    moveUp,
    moveDown,
    action,
    boost,
    shoot,
    jump,
    mustDie,        // should entity die now ?
    reachedStop,    // elevator reached stop point
    reachedStart,   // elevator reached start point
    diagUp,         // slope going up (left toward right)
    diagDown,       // slope going down (left toward right)
    gotHurt,        // something collided with this entity
    onGround,
    applyGravity,
    falling;

    public static boolean debugMode=false;

    public LevelObject(
            float x, float y,
            float topLeftX, float topLeftY,
            float topRightX, float topRightY,
            float downRightX, float downRightY,
            float downLeftX, float downLeftY,
            String type) {


        this.x = x;
        this.y = y;
        this.type = type;

        // ==================================
        // create a polygon around the object
        // ==================================
        poly = new Polygon(new float[]{
                topLeftX, topLeftY,
                topRightX, topRightY,
                downRightX, downRightY,
                downLeftX, downLeftY
        });        
    }

    // ==============================
    // use vector for climbing slopes
    // ==============================
    public Vector2f getVector(){
       if (boost){
            return vec2;
        }else{
            return vec;
        }        
    }  
    
    // =========================
    // entity shield management
    // =========================
    public int getShields() {
        return shields;
    }
    public void setShields(int i) {
        shields = i;
    }
    public void addShields(int i) {
        shields += i;
        if (shields > MAX_SHIELDS)
            shields = MAX_SHIELDS;
    }
    
    public abstract void update(int delta) throws SlickException;
    public abstract void draw(Graphics g);
    
    public boolean isCollisionWith(LevelObject other) throws SlickException {
        return poly.intersects(other.poly);
    }
}

